package shan.rpc.yurpc.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;

import java.nio.charset.Charset;

public class ConfigUtils {

    /**
     * 加载配置对象
     */
    public static <T> T loadConfig(Class<T> tClass,String prefix){
        return loadConfig(tClass,prefix,"");
    }

    /**
     * 加载配置对象，支持区分环境
     */
    public static <T> T loadConfig(Class<T> tClass,String prefix,String environment){
        StringBuilder configFileBuilder=new StringBuilder("application");
        if(StrUtil.isNotBlank(environment)){
            configFileBuilder.append("-").append(environment);
        }
        configFileBuilder.append(".yaml");
//        Props props=new Props(configFileBuilder.toString());
        Props props =new Props(configFileBuilder.toString(), Charset.forName("UTF-8"));
        props.autoLoad(true);
        return props.toBean(tClass,prefix);
    }

}
